<?php
require "../includes/db.php"; 
$mysqli = new MossCMS();
if ($_SESSION[$prefix.'_username'] == ""){  header("Location: ../login.php"); exit;}
if ($_SESSION[$prefix."_security"] < 1){header("location:../login.php?action=5"); exit;}



$action = $_GET['action'];
$news_id = $_GET['id'];

if($action == 'remove' && $news_id != ''){

 //******************  Article Select Query  ***************
$query_news = "SELECT * FROM news WHERE news_id = $news_id";
$result_news = pg_query($connection, $query_news) or die("Error in query: $query_news.". pg_last_error($connection));
$rows_news = pg_num_rows($result_news);
//********************************************************
$newsarr = pg_fetch_array($result_news, NULL, PGSQL_ASSOC);
$title	= $newsarr[news_title];
$date	= $newsarr[news_date];

$s3_delete_file = $newsarr[news_thumb];
$s3_delete_file = $newsarr[news_pic];
require ($s3_upload_delete);


//**************** DELTE FROM DATABASE (NEWS TABLE) ********************************
 $query = "DELETE from news WHERE news_id = '$news_id'";
 pg_query($connection, $query) or die("Error in query: $query.". pg_last_error($connection)); 
//**********************************************************************
//**************** DELTE FROM DATABASE (news_comments TABLE) ********************************
 $query = "DELETE from comments WHERE news_id = '$news_id'";
 pg_query($connection, $query) or die("Error in query: $query.". pg_last_error($connection)); 
//**********************************************************************

$action		= "Deleted News: $title - $news_id";
include ($action_global);

header("location:news_list.php"); exit; } 

$in_page = $_GET['page'];
if ($in_page == "") { $in_page = 0;}
$limit = 50;
$offset = ($limit * $in_page);

if ($in_page == 86) {
$limit = 'ALL';
$offset = 0;}



?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../includes/admin.css"/>
<title><?php echo $global_title;?></title>

<SCRIPT language="JavaScript">
function assure(id)
{
 var where_to= confirm("Do you really want to delete this news article? There is now way to undo this.");
 if (where_to== true)
 {
   window.location="?action=remove&id="+id;
 }
 }
</SCRIPT>

</head>
<body>

<div id="wrap">
	<div id="page-header">
		<?php include('includes/header.php');?>

	</div>
	
	<div id="page-body">
		<div id="tabs">
			<?php $tab="main"; include('includes/header_tabs.php');?>
		</div>

		<div id="acp">
		<div class="panel">
			<span class="corners-top"><span></span></span>
				<div id="content">
				<div id="menu">
						
					<?php include('includes/menu_top.php');?>	
					<?php include('includes/menu_main.php');?>
					</div>
	
					<div id="main">
<a name="maincontent"></a>


	<h1>Manage Docs/Links</h1>
	<a href="doc_add.php">Add Doc/Link</a>

<?php if($tank != ''){
	echo "<div class='successbox'>";
			if($tank == 'ath_activated'){echo "<p class='action_message'>Athlete Activated!</p>";}
			if($tank == 'ath_deactivated'){echo "<p class='action_message'>Athlete Deactivated!</p>";}
	echo "</div>";		
		} ?>
		
				      
       <table class="underline">
          <thead>
          <tr>
          	<th>Title</th>
			<th>Date</th>
			<th>Actions</th>

          </tr>
          </thead>
          <tbody>
          <?php
			$results = $mysqli->doc_list();
      			for($x=0; $x < sizeof($results); $x++) {
				if($class == 'row2'){$class = 'row1';}else{$class = 'row2';}

			$date = date('m/d/Y',(strtotime($results[$x]['content_date'])));
			$title_link = "<a href='../article.php?id=".$results[$x]['content_id']."'>".$results[$x]['content_title']."</a>";
			$img_link = "<a href='../article.php?id=".$results[$x]['content_id']."' target='blank'>Read</a>";
					
		$edit_link = "<a href ='doc_edit.php?id=".$news_id."'>$icon_edit</a>";
		$edit_title = "<a href ='doc_edit.php?id=".$results[$x]['content_id']."'>".$results[$x]['content_title']."</a>";
		$delete_link = "<a href =\"javascript:;\" onclick=\"assure(". $results[$x]['content_id'].");\">$icon_delete</a>";
		echo "<tr class='$class'><td>".$edit_title."</td><td>".$date."</td><td>".$edit_link.$delete_link."</td></tr>";
			}
			?>
			            
    	</tbody>
        </table>

    
		</div><!-- main -->
	</div><!-- content -->
<span class="corners-bottom"><span></span></span>
</div><!-- panel -->
</div><!-- acp -->

	
	<div id="page-footer">
	<?php include('includes/footer.php');?>
				</div>
</div><!-- page-body -->
</div><!-- wrap -->


</body> 
</html>